package com.itheima.注解.demo3;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class AnnoDemo {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
        //get Class Object
        Class<?> aClass = Class.forName("com.itheima.注解.demo3.UseTest");
        //get usetest object
        UseTest o = (UseTest) aClass.newInstance();
        //获取所有方法并封装成数组
        Method[] methods = aClass.getDeclaredMethods();
        //遍历数组,获取每一个method对象
        for (Method method : methods) {
            //判断是否包含test注解
            if (method.isAnnotationPresent(Test.class)){
                //暴力反射
                method.setAccessible(true);
                method.invoke(o);
            }
        }

    }
}
